import 'package:flutter/material.dart';
import 'package:my_app/app/core/utils/object_util.dart';
import 'package:my_app/app/core/theme/app_colors.dart';
import 'package:my_app/app/core/theme/app_text_theme.dart';

class Cell extends StatelessWidget {
  ///左侧标题
  final String? titleText;

  ///标题组件
  final Widget? title;

  ///右侧内容
  final String? valueText;

  ///内容组件
  final Widget? value;

  ///右侧的图标
  final IconData? rightIcon;

  final Widget? right;

  /// 左侧的图标
  final Widget? icon;

  ///标题下方的描述信息
  final Widget? label;

  ///是否显示下边框
  final bool border;

  final VoidCallback? onTap;

  const Cell({
    super.key,
    this.titleText,
    this.valueText,
    this.rightIcon,
    this.icon,
    this.label,
    this.border = true,
    this.title,
    this.value,
    this.right,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Ink(
        padding: EdgeInsets.all(8.0),
        decoration: border
            ? BoxDecoration(
                color: Colors.white,
                border: Border(
                  bottom: BorderSide(color: dividerColor, width: 0.5),
                ),
              )
            : null,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    if (icon != null) icon!,
                    if (icon != null) SizedBox(width: 3.0),
                    if (!ObjectUtil.isEmptyString(titleText) && title == null)
                      Text(titleText!, style: cellTitle),
                    if (title != null) title!,
                  ],
                ),
                if (label != null) SizedBox(height: 3.0),
                if (label != null) label!
              ],
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                if (!ObjectUtil.isEmptyString(valueText) && value == null)
                  Text(valueText!, style: contentText),
                if (value != null) value!,
                SizedBox(width: 5.0),
                if (rightIcon != null && right == null)
                  Padding(
                    padding: const EdgeInsets.only(top: 2.0),
                    child:
                        Icon(rightIcon, color: Color(0xFF909399), size: 15.0),
                  ),
                if (right != null) right!,
              ],
            )
          ],
        ),
      ),
    );
  }
}
